package com.cat.dataStructure03;

import java.util.*;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/all-divisions-with-the-highest-score-of-a-binary-array/
 * @create 2025/11/19 11:08
 * @since JDK17
 */

public class Solution89 {
    public List<Integer> maxScoreIndices(int[] nums) {
        int n = nums.length, sum = Arrays.stream(nums).sum(), zero = 0, max = sum;
        ArrayList<Integer> ans = new ArrayList<>();
        ans.add(0);
        for (int i = 0; i < n; i++) {
            zero += 1 - nums[i];
            int score = zero + sum - (i - zero + 1);
            if (max < score) {
                max = score;
                ans.clear();
                ans.add(i + 1);
            } else if (score == max) {
                ans.add(i + 1);
            }
        }

        return ans;
    }
}
